var removeElement = function(nums, val) {
    var idx = 0
     for (let i = 0; i < nums.length; i++) {
         if (nums[i] !== val) {
             nums[idx++] = nums[i]
         }

     }
    console.log(nums)
     return idx
};

const nums = removeElement([0,1,2,2,3,0,4,2], 2)
console.log(nums)
